package com.framework.test.core;

public class HumpMatcher implements Matcher {

    public boolean match(String columnName, String propertyName) {
        if (columnName == null || propertyName == null) {
            return false;
        }

        // 直接比较，避免不必要的转换
        if (columnName.equals(propertyName)) {
            return true;
        }

        // 转换为驼峰命名并比较
        return convertToHumpCase(columnName).equals(propertyName);
    }

    /**
     * 将下划线命名转换为驼峰命名
     * 优化：使用StringBuilder预分配容量，减少字符串操作
     */
    private String convertToHumpCase(String columnName) {
        String lowerName = columnName.toLowerCase();
        String[] parts = lowerName.split("_");
        
        if (parts.length == 1) {
            return lowerName;
        }
        
        // 预分配StringBuilder容量，减少扩容
        StringBuilder result = new StringBuilder(columnName.length());
        
        for (int i = 0; i < parts.length; i++) {
            String part = parts[i];
            if (!part.isEmpty()) {
                if (i == 0) {
                    result.append(part);
                } else {
                    // 首字母大写
                    result.append(Character.toUpperCase(part.charAt(0)));
                    if (part.length() > 1) {
                        result.append(part.substring(1));
                    }
                }
            }
        }
        
        return result.toString();
    }
}
